package com.atguigu.service_helpcenter.service.impl;

import com.atguigu.service_helpcenter.entity.HelpCenter;
import com.atguigu.service_helpcenter.entity.QueryVo;
import com.atguigu.service_helpcenter.mapper.HelpCenterMapper;
import com.atguigu.service_helpcenter.service.HelpCenterService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.poi.ss.formula.functions.Hlookup;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ZhuangLiJiao
 * @since 2022-01-06
 */
@Service
public class HelpCenterServiceImpl extends ServiceImpl<HelpCenterMapper, HelpCenter> implements HelpCenterService {

    @Autowired
    private HelpCenterMapper helpCenterMapper;


    @Override
    public Page<HelpCenter> pageOrderCondition(long current, long limit, QueryVo queryVo) {

        LambdaQueryWrapper<HelpCenter> wrapper = new LambdaQueryWrapper<>();
        if (queryVo != null) {
            if (!StringUtils.isEmpty(queryVo.getIsSolve())) {
                if (queryVo.getIsSolve().equals("1")) {
                    wrapper.eq(HelpCenter::getIsSolve, "1");
                } else {
                    wrapper.isNull(HelpCenter::getIsSolve);
                }
            }
            if (!StringUtils.isEmpty(queryVo.getName())) {
                wrapper.like(HelpCenter::getName, queryVo.getName());
            }
            if (!StringUtils.isEmpty(queryVo.getContactTel())) {
                wrapper.like(HelpCenter::getContactTel, queryVo.getContactTel());
            }
        }
        wrapper.orderByDesc(HelpCenter::getModifiedTime);
        Page<HelpCenter> page = new Page<>(0, 10);
        helpCenterMapper.selectPage(page, wrapper);
        return page;
    }

    //3.设置为已受理状态
    @Override
    public void setHelpOk(String helpId) {
        HelpCenter helpCenter = new HelpCenter();
        helpCenter.setId(helpId);
        helpCenter.setIsSolve("1");
        helpCenterMapper.updateById(helpCenter);
    }
}
